<?php
class UsersController extends AppController{
    
    public function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->allow('auto','login','mail');
        $this->Security->requireSecure('login');
    }
    
    public function auto(){
        $user = $this->User->find('first', array(
            'conditions' => array('User.role' => 'user')
        ));
        if(!empty($user)){
            $this->Auth->login($user['User']);
        }
    }
    
    public function login(){
        if(!empty($this->request->data)){
            if($this->Auth->login()){
                
            }
        }
    }
    
    public function mail() {        
        App::uses('CakeEmail', 'Network/Email');
        $email = new CakeEmail('gmail');
        $email->from('jailoza77@gmail.com');
        $email->to('jaimeandres@yopmail.com');
        $email->subject('asunto del mensaje');
        $email->send('cuerpo del mensaje');
    }
    
    public function malo(){
        App::uses('CakeEmail', 'Network/Email');
        $email = new CakeEmail('default');
        $email->to('jaimeandres@yopmail.com'
         //       'jaimeandres@yopmail.com'
                );
        $email->subject('Test d\ email para prueba');
        debug($email->send('email de test'));
        die('lol');
    }


    public function logout(){
        $this->Auth->logout();
        return $this->redirect('/');
    }
}

